package jianzhiOffer;

public class Num020 {
    int count = 0;
    public int countSubstrings(String s) {
        char[] chars = s.toCharArray();
        int len = chars.length;
        for(int i = 0; i < len; i++) {
            StringBuilder sb = new StringBuilder();
            for(int j = i; j < len;j++) {
                sb.append(chars[j]);
                if(isHuiWen(sb.toString())) count++;
            }
        }
        return count;
    }

    boolean isHuiWen(String s) {
        int l = 0,r = s.length() - 1;
        while(l < r) {
            if(s.charAt(l) != s.charAt(r)) return false;
            l++;
            r--;
        }
        return true;
    }
}
